package com.ruoyi.web.controller.activiti;

import com.ruoyi.activiti.domain.ActDeploymentVo;
import com.ruoyi.activiti.domain.WorkFlowVo;
import com.ruoyi.activiti.service.WorkFlowService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import org.activiti.engine.repository.Deployment;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("activiti")
public class WorkFlowController extends BaseController {

    @Autowired
    private WorkFlowService workFlowService;

    private String prefix = "activiti";

    /**
     * 加载部署信息
     * @param workFlowVo
     * @return
     */
    @RequestMapping("deploy/list")
    public List<ActDeploymentVo> workFlowVoList(WorkFlowVo workFlowVo) {
        List<ActDeploymentVo> deploymentVoList = workFlowService.deployment(workFlowVo);
        return deploymentVoList;
    }

    @PostMapping(value = "activiti/delete")
    @ResponseBody
    @Log(title = "activiti", businessType = BusinessType.DELETE)
    public AjaxResult delete(WorkFlowVo workFlowVo){
        logger.info(workFlowVo.toString());
        try {
            workFlowService.deleteBatch(workFlowVo);
            return  toAjax(1);
        } catch (Exception e) {
            e.printStackTrace();
            return toAjax(0);
        }
    }
}
